--================================分离器===========================================
function Split(szFullString, szSeparator)
	local nFindStartIndex = 1
	local nSplitIndex = 1
	local nSplitArray = {}
	while true do
		local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
		if not nFindLastIndex then
		nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
		break
		end
		nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
		nFindStartIndex = nFindLastIndex + string.len(szSeparator)
		nSplitIndex = nSplitIndex + 1
	end
	return nSplitArray
end

--===============================格式化字符串=========================================
function format_num( num )
	num = tonumber(num)
	if num < 10 then
		return "0"..num
	end
	return num;
end

--============================判断字符串是否有相交=============================
function is_str_mix( str1, str2 )
	local t1 = ""
	local len1 = string.len(str1)
	local len2 = string.len(str2)

	for i=1,len1,2 do
		t1 = string.sub(str1,i,i+1)
		for j=1,len2,2 do
			if( t1 == string.sub(str2,j,j+1) ) then return 1 end
		end
	end

	return nil
end


--============================数字字符串排序========================
function sort_str( num , max)
	local out = ""
	local st = {}
	if num == nil then return nil end
	local len = string.len( num )
	if len%2 ~= 0 then
		return nil
	end

	for i=1,len,2 do
		c = string.sub(num,i,i+1)
		if tonumber(c) > max or tonumber(c) <1 then return nil end
		if not in_table( c, st ) then
			table.insert( st, c )
		else
			return nil
		end
	end
	table.sort(st)
	for i=1,table.getn( st ) do
		out = out..st[i]
	end
	return out
end

function in_table ( e, t )
	for _,v in pairs(t) do
		if (v==e) then return true end
	end
	return false
end



--========================排列组合 m>=n============================
function permutation( m, n )
	local out=1;
	if m==n then
		for i=1,m do
			out = out*i
		end
	else
		for i=m-n+1,m do
			out = out*i
		end
	end

	return out
end

function combination(m, n)
	--if m == n then return 1 end
	if m < n then return 0 end
	local out = permutation(m, n)
	local out1 = 1;
	for i=1,n do
		out1 = out1*i
	end
	return (out/out1)
end


--========================随机产生可重复的数=====================================
function selectNumber(count,...)
	selected={};
	math.random(0,#arg);
	math.randomseed(microtime()*1000000);
	if #arg<=count then return arg end
	while #selected < count do
		math.random(#arg);
		table.insert(selected,arg[math.random(#arg)]);
	end
	return selected;
end

--========================随机产生不可重复的数===================================
function sel_dist_num(count,...)
	selected={};
	math.random(0,#arg);
	math.randomseed(microtime()*1000000);
	--math.randomseed(os.time());
	if #arg<=count then return arg end
	while #selected < count do
		math.random(#arg);
		table.insert(selected,table.remove(arg,math.random(#arg)));
	end
	return selected;
end


--=========================单式复式计算 bq6 sf14 j4 rx9 pl5=================================================
function MultSimpCompute(jItemstr,djStr,butPower,m,n,butType)
	local queryStr = {}    ---查询指令串
	local bullStr = {}		----开奖指令串
	local bingoNum = 0
	local result = 0
	for i=1,#jItemstr do
		jitemLen = string.len(jItemstr[i])
		queryStr[i]={}
		for j=1,jitemLen, n do
			if n == 1 then
				queryStr[i][j] = string.sub(jItemstr[i],j,j)
			else
				queryStr[i][(j+1)/2] = string.sub(jItemstr[i],j,j+1)
			end
		end
	end

	for i=1, string.len(djStr), n do
		if n == 1 then
			bullStr[i] = string.sub(djStr,i,i)
		else
			bullStr[(i+1)/2] = string.sub(djStr,i,i+1)
		end
	end
	if butType == '1' then
		for i = 1,table.getn(jItemstr) do
			for j,k in ipairs(bullStr) do
				if queryStr[i][j] == k or queryStr[i][j] == '*' or k== '*' then
					bingoNum = bingoNum + 1
				end
			end
			if bingoNum == m then
				bingoNum = 0
				result = result + 1
			end
			bingoNum = 0
		end
		result = result*butPower
	elseif butType == '2' then
			--如果比赛有延期，这这场比赛都默认猜对。中奖注数=1*这场选的个数
			nNum = 1
		for i=1,m do
			for _,k in ipairs(queryStr[i]) do
				if k == bullStr[i] or k == '*' or bullStr[i] == '*' then
					bingoNum = bingoNum + 1
					if bullStr[i] == '*' then
						nNum = nNum * (#queryStr[i])
					end
					break
				end
			end
		end
		if bingoNum == m then
			result = nNum*butPower
		else
			return 0
		end
	elseif butType == '3' then
		for i = 1,table.getn(jItemstr) do
			for _,k in ipairs(bullStr) do
				for _,v in ipairs(queryStr[i]) do
					if v == k then
						bingoNum = bingoNum + 1
					end
				end
			end
			if bingoNum == m then
				bingoNum = 0
				result = result + 1
			end
			bingoNum = 0
		end
		result = result*butPower
	elseif butType == '4' then
		for i = 1,3 do
			for _,k in ipairs(queryStr[1]) do
				if k == bullStr[i] then
					bingoNum = bingoNum + 1
				end
			end
		end
		if bingoNum ~= table.getn(queryStr[1]) then return 0 end
		for i = 1,3 do
			for _,k in ipairs(queryStr[2]) do
				if k == bullStr[i] then
					bingoNum = bingoNum + 1
				end
			end
		end
		if bingoNum == 3 then result = 1 end

	end


	return result

end
--========================dlt================================================
function ConputeBingoNum(jItemstr,djStr,len)
	local bingoNum = 0
	local queryStr = {}    ---查询指令串
	local bullStr = {}

	for i=1,string.len(djStr),len do
		if len == 2 then
			bullStr[(i+1)/2] = string.sub(djStr,i,i+len-1)
		else
			bullStr[i] = string.sub(djStr,i,i+len-1)
		end
	end
	for i=1,string.len(jItemstr) ,len do
		if len == 2 then
			queryStr[(i+1)/2] = string.sub(jItemstr,i,i+len-1)
		else
			queryStr[i] = string.sub(jItemstr,i,i+len-1)
		end
	end
	for i=1,string.len(djStr) / len do
		for _,k in ipairs(queryStr) do
			if k == bullStr[i]  then
				bingoNum = bingoNum + 1
			end
		end
	end

	return bingoNum
end

--====================求m的n次方============================================================
function power(m,n)
	local result = 1
	if n == 0 then
		result = 1
	else
		for i = 1 ,n do
			result = result*m

		end
	end
	return result
end

